const fastShop = {};

fastShop.changeBPLink = function (id, number, skuId) {
  let params = {};
  if (skuId) {
    params = {
      "id": id,
      "skuId": skuId,
      "num": number,
    };
  } else {
    params = {
      "id": id,
      "num": number,
    };
  }

  let result = {};
  const changeLink = threads.start(function () {
    const res = http.post(
      app.versionName == "4.1.1 Alpha2"
        ? "http://xxxx:8000/link/bpLinkChange/"// 本地服务地址
        : "http://xxxx/link/bpLinkChange/"// 服务器端地址,
      params
    );

    if (res.statusCode != 200) {
      toast("请求失败: " + res.statusCode + " " + res.statusMessage);
      result = {
        state: false,
      };
    } else {
      const contents = JSON.parse(res.body.string());
      if (contents.success) {
        result = {
          state: true,
          url: contents.data.url,
        };
      } else {
        result = {
          state: false,
        };
      }
    }
  });
  changeLink.join();
  return result;
};

module.exports = fastShop;
